package com.ronglian.register_mini_program.service.impl;

import com.ronglian.register_mini_program.dao.WxUserAccessTokensMapper;
import com.ronglian.register_mini_program.model.WxUserAccessTokens;
import com.ronglian.register_mini_program.model.WxUserAccessTokensExample;
import com.ronglian.register_mini_program.service.AccessTokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("AccessTokenService")
public class AccessTokenServiceImpl implements AccessTokenService {

    @Autowired
    WxUserAccessTokensMapper accessTokensMapper;

    @Override
    public int insert(WxUserAccessTokens accessTokens) {
        return accessTokensMapper.insert(accessTokens);
    }

    @Override
    public int update(WxUserAccessTokens accessTokens) {
        return accessTokensMapper.updateByPrimaryKey(accessTokens);
    }

    @Override
    public WxUserAccessTokens findByAppid(String wx_app_id) {
        WxUserAccessTokensExample example = new WxUserAccessTokensExample();
        WxUserAccessTokensExample.Criteria criteria = example.createCriteria();
        System.out.println("实现类的appid有没有传过来========="+wx_app_id);
        criteria.andWx_app_idEqualTo(wx_app_id);
        List<WxUserAccessTokens> accessTokensList = accessTokensMapper.selectByExample(example);
        System.out.println("查询到的access_tokenList============"+accessTokensList);
        if (accessTokensList != null && accessTokensList.size() > 0) {
        System.out.println("accesstoken=============="+accessTokensList.size());
            System.out.println("accesstoken=========="+accessTokensList.get(0));
            return accessTokensList.get(0);
        }
        return null;
    }
}
